<?php
namespace app\index\controller;

use app\admin\model\Chanpin;

class ChanpinController extends CommonController
{
    protected $chanpin = null;
    public function _initialize()
    {
        parent::_initialize();
        if ($this->chanpin == null) $this->chanpin = new Chanpin();
    }
    //1.产品列表页面
    public function index()
    {
        //1.取出轮播图
        $data = $this->chanpin->order('id desc')->select();
        $this->assign('data', $data);

        return $this->fetch();
    }

    //2. 详情页面
    public function item($id)
    {
        //判断参数是否合法
        if ( empty($id) || floor($id) != $id ) return $this->redirect(__ROOT__);
        $data = $this->chanpin->find($id);
        $this->assign('data', $data);

        return $this->fetch();
    }

}
